import request from '@/utils/request'

export function getDepartmentYears(params) {
  return request({
    url: 'api/department/years',
    method: 'get',
    params
  })
}

export function getColleges(params) {
  return request({
    url: 'api/department/colleges/',
    method: 'get',
    params
  })
}

export function getMajors(year) {
  return request({
    url: 'api/department/major/' + year,
    method: 'get'
  })
}

export function getDepartments(params) {
  return request({
    url: 'api/department',
    method: 'get',
    params
  })
}

export function getDepartmentTree(params) {
  return request({
    url: 'api/department/tree',
    method: 'get',
    params
  })
}

export function getDepartmentSuperior(ids) {
  const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
  return request({
    url: 'api/department/superior',
    method: 'post',
    data
  })
}

export function add(data) {
  return request({
    url: 'api/department',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: 'api/department/',
    method: 'delete',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: 'api/department',
    method: 'put',
    data
  })
}

export default { add, edit, del, getDepartmentYears, getColleges, getMajors, getDepartmentTree, getDepartments, getDepartmentSuperior }
